import { fileTypeList } from '@/enum'
import { getUserList } from '@/service/user'
import dayjs from 'dayjs'

export default {
  data () {
    return {
      searchData: {
        name: '',
        upTime: ''
      },
      fileTypeList,
      userList: [],
      loading: false,
      curPage: 1,
      pageSize: 10,
      totalPage: 0
    }
  },
  methods: {
    searchUserList () {
      this.curPage = 1
      this.getList()
    },
    // 页码改变
    pageChange (page) {
      this.curPage = page
      this.getList()
    },
    // 获取列表
    getList () {
      // 统一处理列表请求
      const param = {
        ...this.searchData,
        page: this.curPage,
        rows: this.pageSize,
        createTime: this.searchData.upTime ? dayjs(this.searchData.upTime[0]).format('YYYY-MM-DD HH:mm:ss') : ''
      }
      this.loading = true
      getUserList(param).then(res => {
        this.userList = res.data.data.content
        this.totalPage = res.data.data.total
      }).finally(() => {
        this.loading = false
      })
    },
    // 重置搜索
    resetSearch () {
      this.$refs.searchForm.resetFields()
    }
  }
}
